package com.christian.thread.priority;

/**
 * 文件描述：线程的优先级，设置优先级不代表每次都一定会被执行，只是 CPU 调度时会优先分配
 *
 * @Author：wang
 * @Date：2020-01-14 21:16:57
 */
public class PriorityCase {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {

            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + " : " + i);
            }
        }, "Thread1");

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + " : " + i);
            }
        }, "Thread2");

        //设置线程的优先级，参数越大优先级越到
        t1.setPriority(Thread.MIN_PRIORITY);
        t2.setPriority(Thread.MAX_PRIORITY);

        t1.start();
        t2.start();
    }
}
